import { Component, OnInit } from '@angular/core';
import { NzMessageService, NzModalRef } from 'ng-zorro-antd';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';

@Component({
  selector: 'app-confirm',
  templateUrl: './interaction-modal.component.html',
  styles: [],
})
export class InteractionModalComponent implements OnInit {

  remark: any = {};
  validateForm: FormGroup;
  isLoading: boolean = false;

  constructor(private fb: FormBuilder,
              private modal: NzModalRef,
              public message: NzMessageService,
  ) {
  }

  ngOnInit(): void {
    this.validateForm = this.fb.group({
      remark: [this.remark, [Validators.required, Validators.maxLength(100)]],
    });
  }

  submitForm(): void {
    if (this.validateForm.invalid) {
      for (const i in this.validateForm.controls) {
        this.validateForm.controls[i].markAsDirty();
        this.validateForm.controls[i].updateValueAndValidity();
      }
    } else {
      this.modal.close(this.validateForm.value.remark);
    }
  }

  close() {
    this.modal.destroy();
  }

}
